package com.battle.service.controller.web;

import com.battle.pojo.param.questionBank.*;
import com.battle.pojo.vo.questionBank.*;
import com.battle.service.service.in.*;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.util.List;

/**
 * web/题库
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/questionBank/web")
public class QuestionBankWebController {

    private final QuestionBankService service;

    public QuestionBankWebController(QuestionBankService service) {
        this.service = service;
    }


    /**
     * 创建题库
     *
     * @param param
     * @return
     */
    @PostMapping("/createQuestionBank")
    public ApiResult createQuestionBank(@RequestBody @Valid CreateQuestionBankParam param) {
        service.createQuestionBank(param);
        return ApiResult.ok();
    }


    /**
     * 修改题库
     *
     * @param param
     */
    @PutMapping("/editQuestionBank")
    public ApiResult editQuestionBank(@RequestBody @Valid EditQuestionBankParam param) {
        service.editQuestionBank(param);
        return ApiResult.ok();
    }

    /**
     * 移除题库
     *
     * @param id
     */
    @DeleteMapping("/removeQuestionBank")
    public ApiResult removeQuestionBank(@RequestParam("id") Long id) {
        service.removeQuestionBank(id);
        return ApiResult.ok();
    }

    /**
     * 启动/禁用题库
     *
     * @param id
     */
    @GetMapping("/enabledQuestionBank")
    public ApiResult enabledQuestionBank(@RequestParam("id") Long id) {
        service.enabledQuestionBank(id);
        return ApiResult.ok();
    }

    /**
     * 获取题库详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getQuestionBank")
    public ApiResult<GetQuestionBankVo> getQuestionBank(@RequestParam("id") Long id) {
        GetQuestionBankVo vo = service.getQuestionBank(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取题库列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getQuestionBankList")
    public ApiResult<PageResult<GetQuestionBankListVo>> getQuestionBankList(@RequestBody GetQuestionBankListParam param) {
        PageResult<GetQuestionBankListVo> result = service.getQuestionBankList(param);
        return ApiResult.ok(result);
    }


    /**
     * 获取题库下拉列表
     *
     * @return
     */
    @PostMapping("/getQuestionBankDownList")
    public ApiResult<List<GetQuestionBankDownListVo>> getQuestionBankDownList(@RequestBody(required = false) @Valid GetQuestionBankDownListParam param) {
        List<GetQuestionBankDownListVo> list = service.getQuestionBankDownList(param);
        return ApiResult.ok(list);
    }


}

